/*
 * Copyright 2016 Daniel Bechler
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package de.danielbechler.diff.category

import de.danielbechler.diff.ObjectDifferBuilder
import de.danielbechler.diff.introspection.ObjectDiffProperty
import de.danielbechler.diff.path.NodePath
import spock.lang.Specification

class CategoriesTestIT extends Specification {

	def "should return all categories"() {
		setup:
		  def obj1 = new MyObject("aaa", "aaa")
		  def obj2 = new MyObject("bbb", "bbb")
		  def differ = ObjectDifferBuilder.startBuilding()
				  .categories()
				  .ofNode(NodePath.with("firstString")).toBe("cat1")
				  .ofNode(NodePath.with("secondString")).toBe("cat1")
				  .and()
				  .build()
		  def node = differ.compare(obj1, obj2)

		expect:
		  node.getChild("firstString").getCategories() == ["cat1"] as Set
		  node.getChild("secondString").getCategories() == ["cat1", "catAnnotation"] as Set
	}

	@SuppressWarnings("GroovyUnusedDeclaration")
	class MyObject {
		def firstString
		def secondString

		MyObject(firstString, secondString) {
			this.firstString = firstString
			this.secondString = secondString
		}

		@ObjectDiffProperty(categories = ["catAnnotation"])
		def getSecondString() {
			return secondString
		}

		void setSecondString(secondString) {
			this.secondString = secondString
		}
	}
}
